package com.seal.dao;

import java.io.Serializable;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author meng.xf
 *
 */
public class BaseDaoImpl implements IDao {
	
	protected static final Log log = LogFactory.getLog("DAO");
	
	@Autowired(required = true)
	private SessionFactory sessionFactory;
	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public Session getSession(){
		return sessionFactory.getCurrentSession();
	}

	public void delete(Object obj) throws Exception {
		getSession().delete(obj);
	}


	public void save(Object obj) throws Exception {
		getSession().save(obj);
	}


	public void saveOrUpdate(Object obj) throws Exception {
		getSession().saveOrUpdate(obj);
	}


	@SuppressWarnings("unchecked")
	public Object select(Class cls, Serializable primaryKey) throws Exception {
		return getSession().get(cls,primaryKey);
	}


	public void update(Object obj) throws Exception {
		getSession().update(obj);
	}

}
